#include "stdafx.h"
#include "CdnProfTimer.h"

namespace prof
{
	

	//-----------------------------------------------------
	/**
	* Ctor
	*/
	CdnProfTimer::CdnProfTimer()
		: m_tick(LONGLONG()),
		m_frequency(0.0f),
		m_time(0.0f)
	{
		LONGLONG ticksPerSec;
		QueryPerformanceFrequency((LARGE_INTEGER*)&ticksPerSec);
		m_frequency = 1.0f / (float)ticksPerSec;
	}

	//-----------------------------------------------------
	/**
	* Dtor
	*/
	CdnProfTimer::~CdnProfTimer()
	{

	}

	//-----------------------------------------------------
	/**
	* Initializes timer
	*/
	void CdnProfTimer::StartTimer()
	{			
		QueryPerformanceCounter((LARGE_INTEGER*)&m_tick);
		m_time = (float)m_tick * m_frequency;
	}

	//-----------------------------------------------------
	/**
	* Gets elapsed time since timer started in seconds
	*/
	float CdnProfTimer::GetElapsedTime()
	{
		QueryPerformanceCounter((LARGE_INTEGER*)&m_tick);
		float currentTime = (float)m_tick * m_frequency;
		return currentTime - m_time;
	}
}
